package youcaihuaoa.weetop.com.ui.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.QxsxDataBean
import youcaihuaoa.weetop.com.R

class TreeViewAdapter2 :
    BaseQuickAdapter<QxsxDataBean, BaseViewHolder>(R.layout.app_item_tree_view) {


    override fun convert(holder: BaseViewHolder, item: QxsxDataBean) {
        val disclosureImg = holder.getView<ImageView>(R.id.disclosureImg)
        val contentText = holder.getView<TextView>(R.id.contentText)
        val iv_select = holder.getView<ImageView>(R.id.iv_select)
        iv_select.isSelected = item.select
        contentText.text = item.name
        holder.itemView.isEnabled = item.enable
        iv_select.isEnabled = item.enable
        val item_mRv = holder.getView<RecyclerView>(R.id.item_mRv)
        iv_select.setOnClickListener {
            if(getOnItemClickListener()!=null){
                getOnItemClickListener()?.onItemClick(this, it, holder.adapterPosition)
            }
        }

        if (item.son_menu_data.isNullOrEmpty()) {
            //这里要主动设置一下icon可见，因为convertView有可能是重用了"设置了不可见"的view，下同。
            disclosureImg.setImageResource(R.mipmap.app_ic_treen_close)
            disclosureImg.visibility = View.INVISIBLE
            item_mRv.visibility = View.GONE
        } else {
            if (item.expanded) {
                disclosureImg.setImageResource(R.mipmap.app_ic_treen_open)
                disclosureImg.visibility = View.VISIBLE
                item_mRv.visibility = View.VISIBLE
            } else {
                disclosureImg.setImageResource(R.mipmap.app_ic_treen_close)
                disclosureImg.visibility = View.VISIBLE
                item_mRv.visibility = View.GONE
            }
        }
    }
}